package com.hopes.bizz.risk.control.evaluate;

import com.hopes.bizz.risk.control.bo.NegatedItem;
import com.hopes.bizz.risk.control.bo.RiskEffectEvaluationScore;
import com.hopes.bizz.risk.control.bo.RiskEvaluateBo;
import com.hopes.bizz.risk.control.service.RiskMeasureTaskRecordService;
import com.hopes.bizz.risk.control.service.RiskObjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author lyb
 * @version 1.0
 * @description: 移动终端数量少于安全风险分析对象数量
 * @date 2023/7/6
 */

@Component
@Slf4j
@Order(1006)
public class RiskMobileTerminalRejectFactorHandler extends RiskRejectFactorHandler {

    @Resource
    private RiskMeasureTaskRecordService riskMeasureTaskRecordService;

    @Resource
    private RiskObjectService riskObjectService;

    @Override
    protected NegatedItem doCalculate(RiskEvaluateBo riskEvaluateBo, NegatedItem negatedItem) {
        Date startTime = riskEvaluateBo.getStartTime();
        Date endTime = riskEvaluateBo.getEndTime();
        Long imeiCount = riskMeasureTaskRecordService.countImeiLimitTime(startTime, endTime);
        long objectCount = riskObjectService.count();
        if (imeiCount.intValue() < objectCount) {
            log.info("风险分析对象数量小于imei数量");
            negatedItem.setNegatedItemSix(Boolean.FALSE);
            negatedItem.setNegatedItemSixReason("移动终端数量少于安全风险分析对象数量,本周使用" + imeiCount + "个移动端排查任务,风险分析对象有" + objectCount + "个");
        }
        return doNextCalculate(riskEvaluateBo, negatedItem);
    }

    @Override
    protected Boolean isUse(RiskEffectEvaluationScore riskEffectEvaluationScore) {
        return riskEffectEvaluationScore.getMobileTerminalFlag();
    }
}
